/* 
 * File:   math_macros.h
 * Author: gustavo
 *
 * Created on December 30, 2011, 2:41 AM
 */

#ifndef MATH_MACROS_H
#define	MATH_MACROS_H


//
//namespace math {
//
//	static const double PI = 3.14159265358979323846;
//
//	template <typename T> inline static T max(T a, T b) {
//		return (a > b) ? a : b;
//	}
//
//	template <typename T> inline static T min(T a, T b) {
//		return (a < b) ? a : b;
//	}
//
//	template <typename T> inline static T abs(T a) {
//		if (a < 0) return -a;
//		else return a;
//	}
//
//	template <typename T> inline static T sign(T a) {
//		return a < 0 ? -1 : 1;
//	}
//
//	template <typename T> inline static T clamp(T x, T low, T high) {
//		if (x < low) return low;
//		if (x > high) return high;
//		return x;
//	}
//
//	template <typename T> inline static T ceil(T a) {
//
//		if ((a - long(a) != 0)) {
//			if (a > 0) return T(long(a + 1));
//			else return T(long(a));
//		}
//
//		return (long) a;
//
//		//return (a - (long) a) != 0 ? ((a > 0) ? (long) a + 1 : (long) a) : (long) a;
//	}
//
//	template <typename T> inline static T floor(T a) {
//
//		if ((a - (long) a != 0)) {
//			if (a < 0) return (long) (a - 1);
//			else return (long) a;
//		}
//		return (long) a;
//
//		//return (a - (long) a) != 0 ? ((a < 0) ? (long) a - 1 : (long) a) : (long) a;
//	}
//
//	template <typename T> inline static T fix(T a) {
//
//		if (a > 0) return floor(a);
//		else return ceil(a);
//
//	}
//
//	template <typename T> inline static T round(T a) {
//
//		if ((a - long(a)) >= 0) return T(long(a + 0.5));
//		else return T(long(a - 0.5));
//
//	}
//
//	template <typename T> inline static T rad2deg(T a) {
//
//		return a * 180.0 / PI;
//
//	}
//
//	template <typename T> inline static T deg2rad(T a) {
//
//		return a * PI / 180.0;
//
//	}
//
//}

// = Common comparations ===================================================
#ifndef min
#define min(a,b)	( (a)<(b) ? (a) : (b) )
#endif

#ifndef max
#define max(a,b)	( (a)>(b) ? (a) : (b) )
#endif

#ifndef __xor
#define __xor( a, b ) ( !(a) ^ !(b) )
#endif

#ifndef abs
#define abs(a)		( (a)< 0 ? -(a) : (a) )
#endif

#ifndef sign
#define sign(a)		( (a)< 0 ? -1 : 1 )
#endif

#ifndef sqr
#define sqr(a)   ( (a)*(a) )
#endif

#ifndef clamp
#define clamp(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#endif

#define ceil(a)		( ( ( (a)-(long)(a) ) != 0 )	?	( (a)>0	? (long)(a)+1 : (long)(a) )	:	( (long)(a) ) )

#define floor(a)	( ( ( (a)-(long)(a) ) != 0 )	?	( ( (a)<0 )	?	( (long)(a)-1 )	:	( (long)(a) ) )	:	( (long)(a) ) )

#define fix(a)		((a)>0)		?	FLOOR(a)		:	CEIL(a)
#define round(a)	((a)>=0)	?	(long)((a)+0.5)	: (long)((a)-0.5)

#ifndef M_PI
#define M_PI		3.14159265358979323846	/* pi */
#endif

#define rad2deg(r) (r)*180/M_PI
#define deg2rad(r) (r)*M_PI/180


#endif	/* MATH_MACROS_H */

